home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / miscellaneous / example2.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  3KB  |  99 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: Miscellaneous               Tulevagen 22       */
  8. /* File:    Example2.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-09-26                                       */
  11. /* Version: 1.0                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to execute "Shell" commands  */
  21. /* from a C program with the help of the "Execute() function. */
  22.  
  23.  
  24.  
  25. /* Include the dos library definitions: */
  26. #include <dos/dos.h>
  27.  
  28. /* Now we include the necessary function prototype files:         */
  29. #include <clib/dos_protos.h>       /* General dos functions...    */
  30. #include <clib/exec_protos.h>      /* System functions...         */
  31. #include <stdio.h>                 /* Std functions [printf()...] */
  32. #include <stdlib.h>                /* Std functions [exit()...]   */
  33.  
  34.  
  35.  
  36. /* Set name and version number: */
  37. UBYTE *version = "$VER: AmigaDOS/Miscellaneous/Example2 1.0";
  38.  
  39.  
  40.  
  41. /* Declared our own function(s): */
  42.  
  43. /* Our main function: */
  44. int main( int argc, char *argv[] );
  45.  
  46.  
  47.  
  48. /* Main function: */
  49.  
  50. int main( int argc, char *argv[] )
  51. {
  52.   /* Store the result code here: */
  53.   BOOL ok;
  54.   
  55.   /* A "BCPL" pointer to our Console Window: */
  56.   BPTR my_console;
  57.  
  58.  
  59.  
  60.   /* Open a Console Window to which we will sent the output to: */
  61.   my_console = Open( "CON:10/40/600/150/Example2/CLOSE/WAIT", MODE_NEWFILE );
  62.  
  63.   /* Have we successfully opened the Console Window? */
  64.   if( !my_console )
  65.   {
  66.     /* Error! Inform the user: */
  67.     printf( "Error! Could not open the Console Window!\n" );
  68.  
  69.     /* Exit with an error code: */
  70.     exit( 20 );
  71.   }
  72.  
  73.  
  74.   
  75.   /* Execute the "Shell" command "Dir". We do not use */
  76.   /* and "input" handler, and the "output" should be  */
  77.   /* sent to our Console Window.                      */
  78.   ok = Execute( "C:Dir RAM:", NULL, my_console );
  79.  
  80.   /* OK? */
  81.   if( ok )
  82.     printf( "The \"Shell\" command was successfully executed!\n" );
  83.   else
  84.     printf( "Error! Could not execute the \"Shell\" command!\n" );
  85.  
  86.  
  87.  
  88.   /* Close the Console Window: (Since we have put a    */
  89.   /* "Close" gadget on it and told the window to wait  */
  90.   /* for the user to close it, only the "handler"      */
  91.   /* will be closed. The actual window is first closed */
  92.   /* when the user selects the Close gadget.)          */
  93.   Close( my_console );
  94.  
  95.   /* The End! */
  96.   exit( 0 );
  97. }
  98.  
  99.